package recallin.database;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Comparator;
import java.util.Date;

/**
 * A object of Friends. This used for saving information into the db4o connection.
 * @author philipmasek
 *
 */

public class Friends implements Comparable<Friends>, Comparator<Friends> {
	
	public static final int NEW = 1;
	public static final int DELETED = -1;
	public static final int NUTURAL = 0;
	public static final int CHANGED = 2;
	
	
	private int user_id;
	private String name;
	private String phone_number = null;
	private String email = null;
	private double longitude = 0.0;
	private double latitude = 0.0;
	private String last_time = null;
	private double location_accuracy = 0.0;
	private int request_status;
	private int me_request;
	private int hidden_all = 0;
	private int me_hidden = 0;
	private int hidden_friend = 0;
	private int avatarId;
	private int status = NUTURAL;
	private String tempLastSeen;
	private String tempAddress;
	private String tempStatus;
	
	public Friends(int user_id, String name, String phone_number, String email,
			double longitude, double latitude, String last_time,
			double location_accuracy, int hidden_all, int request_status,
			int hidden_friend, int me_hidden, String tempLastSeen, int me_request) {
		this.user_id = user_id;
		this.name = name;
		this.phone_number = phone_number;
		this.email = email;
		this.longitude = longitude;
		this.latitude = latitude;
		this.last_time = last_time;
		this.location_accuracy = location_accuracy;
		this.setRequest_status(request_status);
		this.setMe_request(me_request);
		this.hidden_all = hidden_all;
		this.me_hidden = me_hidden;
		this.hidden_friend = hidden_friend;
		this.tempLastSeen = tempLastSeen;
	}

	public Friends(int user_id, String name, String phone_number,
			double location_accuracy, String last_time, double longitude,
			double latitude, int avatarId) {
		this.user_id = user_id;
		this.name = name;
		this.phone_number = phone_number;
		this.longitude = longitude;
		this.latitude = latitude;
		this.last_time = last_time;
		this.location_accuracy = location_accuracy;
		this.avatarId = avatarId;
	}

	public Friends(int user_id, String name, String phone_number, String email,
			int hidden_all) {
		super();
		this.user_id = user_id;
		this.name = name;
		this.phone_number = phone_number;
		this.email = email;
		this.hidden_all = hidden_all;
	}

	public Friends(int user_id, String name) {
		this.user_id = user_id;
		this.name = name;
	}

	public int getUser_id() {
		return user_id;
	}

	public void setUser_id(int user_id) {
		this.user_id = user_id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPhone_number() {
		return phone_number;
	}

	public void setPhone_number(String phone_number) {
		this.phone_number = phone_number;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public double getLongitude() {
		return longitude;
	}

	public void setLongitude(double longitude) {
		this.longitude = longitude;
	}

	public double getLatitude() {
		return latitude;
	}

	public void setLatitude(double latitude) {
		this.latitude = latitude;
	}

	public String getLast_time() {
		return last_time;
	}

	public void setLast_time(String last_time) {
		this.last_time = last_time;
	}

	public double getLocation_accuracy() {
		return location_accuracy;
	}

	public void setLocation_accuracy(double location_accuracy) {
		this.location_accuracy = location_accuracy;
	}

	public int getHidden_all() {
		return hidden_all;
	}

	public void setHidden_all(int hidden_all) {
		this.hidden_all = hidden_all;
	}

	public int getMe_hidden() {
		return me_hidden;
	}

	public void setMe_hidden(int me_hidden) {
		this.me_hidden = me_hidden;
	}

	public int getHidden_friend() {
		return hidden_friend;
	}

	@Override
	public int compareTo(Friends o) {
		String[] formats = { "year", "month", "day", "hour", "minute",
				"second", "milisecond" };

		DateFormat dateFormat = new SimpleDateFormat("yyyy MM dd HH mm ss mm");
		if (this.user_id == o.getUser_id())
			return 0;
		else
			try {
				
				return dateFormat.parse(this.getLast_time().replace('-', ' ').replace(':', ' ').replace('.', ' ')).compareTo(dateFormat.parse(o.getLast_time().replace('-', ' ').replace(':', ' ').replace('.', ' ')));
			} catch (ParseException e) {
				return 1;
			}
	}

	// Sort by name
	// @Override
	// public int compareTo(Friends o) {
	// if(this.user_id == o.getUser_id())
	// return 0;
	// else
	// return this.getName().compareTo(o.getName());
	// }

	public int getAvatarId() {
		return avatarId;
	}

	public void setAvatarId(int avatarId) {
		this.avatarId = avatarId;
	}

	@Override
	public int compare(Friends lhs, Friends rhs) {

		return lhs.getName().compareTo(rhs.getName());
	}

	public String getTempLastSeen() {
		return tempLastSeen;
	}

	public void setTempLastSeen(String tempLastSeen) {
		this.tempLastSeen = tempLastSeen;
	}

	public int getRequest_status() {
		return request_status;
	}

	public void setRequest_status(int request_status) {
		this.request_status = request_status;
	}

	public int getMe_request() {
		return me_request;
	}

	public void setMe_request(int me_request) {
		this.me_request = me_request;
	}

	public String getTempAddress() {
		return tempAddress;
	}

	public void setTempAddress(String tempAddress) {
		this.tempAddress = tempAddress;
	}

	public String getTempStatus() {
		return tempStatus;
	}

	public void setTempStatus(String tempStatus) {
		this.tempStatus = tempStatus;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}


}
